<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    .box {
      width: 100px;
      height: 100px;
      background: palegreen;
      position: fixed;
    }
  </style>
</head>
<body>
  <div class="box"></div>
</body>
</html>
<script>
// 英文：
  // distance  距离

const box = document.querySelector('.box');


function move(box, type, targetDistance) {
  box.addEventListener('click', e => {
    let distance = 0;

    const timeId = setInterval(() => {
      distance += 5;

      box.style[type] = distance + 'px';

      if (distance > targetDistance) {
        clearInterval(timeId);
      }
    }, 1000 / 60)
  });
}

// 案例1： 从上向下，移动 600 像素
// move(box, 'top', 600);

// 案例2：从左往右 移动400像素
// move(box, 'left', 400);


// 案例3：案例1 + 案例2



</script>